@extends('Admin.base')
@section('css')
    <link rel="stylesheet" href="/Admin/layuiadmin/css/extend/formSelects-v4.css" media="all">
@endsection
@section('style')
    <style>
        .layui-input {
            display: block;
            width: 62%;
            height: 28px;
            padding-left: 10px;
        }
        .layui-form-item .layui-form-label {
            text-overflow: ellipsis;
            /* overflow: hidden; */
            white-space: nowrap;
        }
        .layui-form-label {
            float: left;
            display: block;
            padding: 9px 15px;
            width: 105px;
            font-weight: 400;
            line-height: 20px;
            text-align: right;
        }

    </style>
@endsection
@section('content')
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form" id="layui-form" action="{{route('goods.configsave',['id' =>$id])}}" method="post">
                <div class="layui-form-item">
                    <label class="layui-form-label">
                        @if($id == 1)
                            输入品牌名称
                        @elseif($id==2)
                            请输入产地名称
                        @elseif($id==3)
                            请输入功效名称
                        @endif
                    </label>
                    <div class="layui-input-block" >
                        <input type="text" name="name" lay-verify="required" value="" class="layui-input" >
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" id="uploadbrand" >添加相应图片</label>
                    <div class="layui-input-block" >
                        <div class="layui-upload">
                        <div class="layui-upload-list">
                        <button type="button"  id="uploadPhoto"  >
                        <img class="layui-upload-img" id="uploadPhoto-img" width="80" height="80" src="http://ccvs-oss.oss-cn-hangzhou.aliyuncs.com/goods/d7NzLMLVweSouv7VZ0mByYjI2fTShEWrjFQUugnC.png">
                        </button>
                        <input type="hidden" id = 'photo' name="photo" value="" lay-verify="required">
                        </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block"> {{csrf_field()}}
                        <button type="reset" class="layui-btn layui-btn-primary">取消</button>
                        <button type="submit" class="layui-btn" lay-submit="" lay-filter="layui-form-submit" >添加</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
@endsection
@section('script')
    <script src="/js/ajax.js"></script>
    <script>
        layui.use(['upload', 'table','layer'],function(){
            var upload = layui.upload;
            var $ = layui.jquery, layer = layui.layer;

          var uploadInst = upload.render({
            elem: '#uploadPhoto' //绑定元素
                    ,url:  '/admin/goods/uploadConfig'
                    ,field: 'brand' //设定文件域的字段名
                    ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#uploadPhoto-img').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                if(res.code > 0){
                    $("#photo").val(res.data);
                    layer.msg('上传成功');
                    layer.closeAll();
                }
                return layer.msg('上传失败');
            }
        });



        });
    </script>

@endsection